home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / basic / pair.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  826b  |  52 lines

  1. #include <LEDA/list.h>
  2.  
  3. class pair {
  4.  
  5.  double  x;
  6.  double  y;
  7.  
  8. public:
  9.  
  10. pair() { x = y = 0; }
  11. pair(const pair& p) { x = p.x; y = p.y; }
  12.  
  13. friend istream& operator>>(istream& is, pair& p)
  14. { return is >> p.x >> p.y; }
  15.  
  16. friend ostream& operator<<(ostream& os, const pair& p)
  17. { return os << p.x << " " << p.y; }
  18.  
  19. friend int compare(const pair&, const pair&);
  20.  
  21. };
  22.  
  23. void Print(const pair& p, ostream& out)  { out << p; } 
  24. void Read(pair& p, istream& in)  { in >> p; } 
  25.  
  26.  
  27. int    compare(const pair& p, const pair& q)
  28. {  if (p.x < q.x) return -1; 
  29.    if (p.x > q.x) return  1; 
  30.    if (p.y < q.y) return -1; 
  31.    if (p.y > q.y) return  1; 
  32.    return 0;  
  33. }
  34.  
  35.  
  36. #if !defined(__TEMPLATE_FUNCTIONS__)
  37. LEDA_TYPE_PARAMETER(pair)
  38. #endif
  39.  
  40.  
  41. main()
  42. {
  43.    list<pair> L;
  44.  
  45.    L.read("list of pairs: ");
  46.    L.sort();
  47.    L.print("sorted:\n",'\n');
  48.  
  49.  }
  50.  
  51.  
  52.